package com.hunter.center.user.util;

import java.util.Properties;
import java.util.ResourceBundle;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import com.security.encrypt.Encoding;


public class EncryptablePropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer{

    @Override
    protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
            throws BeansException {
        System.out.println("EncryptablePropertyPlaceholderConfigurer's class...");
        ResourceBundle paramsBundle = ResourceBundle.getBundle("params");
        String key = paramsBundle.getString("encrypt.desc.key");
        String password = props.getProperty("jdbc.password");
        if (StringUtils.isNotEmpty(password) && StringUtils.isNotEmpty(key)) {
            // 这里可以加密
            props.setProperty("jdbc.password", Encoding.decryptToStr(password, key));
        }
        super.processProperties(beanFactoryToProcess, props);
    }
}
